﻿using System;
using System.Xml.Serialization;
using PrearrangedChaos.AgileZen.Service.Rest;

namespace PrearrangedChaos.AgileZen.Service.Model
{
    [XmlType(AnonymousType = true)]
    [XmlRoot(ElementName = "phase", Namespace = "", IsNullable = false)]
    [ZenRestRequest("projects/{ProjectId}/phases/{PhaseId}")]
    public class PhaseUpdater : IPhaseUpdater
    {
        private int? _limit;

        private string _description;

        /// <remarks/>
        [XmlElement(ElementName = "description")]
        public string Description
        {
            get { return _description; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _description = value;
                else
                    _description = null;
            }
        }

        public bool DescriptionSpecified { get { return this.Description != null; } }

        /// <remarks/>
        [XmlElement(ElementName = "id")]
        public int Id { get; set; }

        public bool IdSpecified { get { return true; } }

        /// <remarks/>
        [XmlElement(ElementName = "index")]
        public int Index { get; set; }

        public bool IndexSpecified { get { return this.Index > 0; } }

        /// <remarks/>
        [XmlElement(ElementName = "limit")]
        public string LimitXmlElement
        {
            get
            {
                if (_limit == null)
                    return null;

                return _limit.Value.ToString();
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                    _limit = null;
                else
                    _limit = Int32.Parse(value);
            }
        }

        /// <remarks/>
        [XmlIgnore]
        public int? Limit
        {
            get { return _limit; }
            set { _limit = value; }
        }

        public bool LimitSpecified { get { return this.Limit != null; } }
    }
}